/*
 * SmartCardFileNode.java
 *
 * Created on 14. November 2006, 15:06
 *
 *
 * SmartCardFileNode represent a TreeNode in a DefaultMutableTreeNode
 * It defines if the Node is a child or not and set the real SmartCardFile 
 * as a userObject in this node. 
 * So the real File is the SmartCardFile. SmartCardFileNode ist the graphical
 * Node in the Tree.
 *
 *  This file is part of JSmex.
 *
 *  JSmex is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  JSmex is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

package jsmex.function;

import javax.swing.tree.DefaultMutableTreeNode;

/**
 *
 * @author Tobias Senger
 */
public class SmartCardFileNode extends DefaultMutableTreeNode {
    
    private boolean explored = false;
    
    /** Creates a new instance of SmartCardFileNode */
    public SmartCardFileNode(SmartCardFile file) {
        setUserObject(file);
    }
    
    public boolean getAllowsChildren() { return isDirectory(); }
    public boolean isLeaf() { return !isDirectory(); }
    public SmartCardFile getFile() { 
        return (SmartCardFile)getUserObject();
    }
    
    public boolean isExplored() { return explored; }
    
    private boolean isDirectory() {
        SmartCardFile file = getFile();
        boolean id = file.isDirectory();
        return id;
    }
    
    public String toString() {
        SmartCardFile file = (SmartCardFile)getUserObject();
        String filename = file.toString();
        return filename;
    }
    
    public void explore() {
        if(!isExplored()) {
            SmartCardFile file = getFile(); // aktuelles File holen
            SmartCardFile[] children = file.listFiles(); // liste aller unterfiles holen.
            if (children!=null) {
                for (int i=0; i < children.length; ++i) 
                    add(new SmartCardFileNode(children[i]));
            
                explored = true;
            }
        }
    }

    
    
}
